﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//using Model;

/// <summary>
/// Description résumée de NavireManager
/// </summary>
/// 
namespace DAL
{

    public class NavireManager : INavireManager
    {
        private IAATOEntities dbService;

        public NavireManager()
        {
            dbService = new IAATOEntities();
        }
        
        public bool addNavire(NAVIRE navire)
        {
            try
            {
                dbService.NAVIREJeu.AddObject(navire);
                dbService.SaveChanges();

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public bool deleteNavire(int navireId)
        {
            try
            {
                NAVIRE navire = (from n in dbService.NAVIREJeu
                                 where n.ID == navireId
                                 select n).First();

                dbService.DeleteObject(navire);
                dbService.SaveChanges();
                return true;
            }

            catch (Exception ex)
            {
                return false;
            }

        }

        public List<NAVIRE> getAllNavires()
        {
            try
            {
                return (from n in dbService.NAVIREJeu
                        orderby n.NOM
                        select n).ToList();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public bool updateNavire()
        {
            try
            {
                dbService.SaveChanges();
                return true;
            }

            catch (Exception ex)
            {
                return false;
            }
        }

        public NAVIRE getNavireById(int id)
        {
            try
            {
                return (from n in dbService.NAVIREJeu
                        where n.ID == id
                        select n
                            ).First();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public List<NAVIRE> getNaviresByCompagnieId(int compagnieId)
        {
            try
            {
                return (from n in dbService.NAVIREJeu
                        where n.COMPAGNIEID == compagnieId
                        orderby n.NOM
                        select n).ToList();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

    }
}